const path = require('path')

function resolve(dir) {
    return path.join(__dirname, dir)
}
//项目名称
const title = "安道教育"
//代理
const proxyTargetMap = {
    prod: 'https://xxx.xxx.com/',
    xuelian: 'http://192.168.5.177',
    yourname:'http://192.168.0.17'
}

let proxyTarget = proxyTargetMap[process.env.API_TYPE] || proxyTargetMap.prod

module.exports = {
    configureWebpack: {
        name: title  //使用<title><%= webpackConfig.name %></title>
    },

    chainWebpack(config) {
        // 移除 prefetch 插件,解决组件懒加载失效的问题
        config.plugins.delete('prefetch')
        //修改svg规则
        config.module.rule('svg')
            //排除自定义的svg文件
            .exclude.add(resolve('src/icons'));
        //新增规则
        // 添加新的svg-sprite-loader处理svgIcon
        // npm i svg-sprite-loader
        config.module.rule('icons')
            .test(/\.svg$/)
            .include.add(resolve('src/icons'))
            .end()
            .use('svg-sprite-loader')
            .loader('svg-sprite-loader')
            .options({ symbolId: 'icon-[name]' })
            .end()
    },

    devServer:{
        open:false,
        proxy:{
            '/api':{
                target:proxyTarget,
                changeOrigin:true,
                pathRewrite:{
                    '^/api':''
                }
            }
        }
    },
    
    pluginOptions: {
        'style-resources-loader': {
          preProcessor: 'scss',
          patterns: [path.resolve(__dirname,"src/assets/styles/var.scss")]
        }
      }
   
}
